package com.csxh;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class BianMa {
public static void main(String[] args) throws IOException {
	//作业：请将utf-8编码的文件utf8.txt的内容--->以gbk编码的文件gbk.txt
			File file = new File("utf8.txt");
			if(!file.exists()){
				file.createNewFile();
				OutputStream out = new FileOutputStream(file);
				String bs = "白日依山尽黄河入海流";
				byte [] b = bs.getBytes("utf-8");
				out.write(b);
			}
			InputStream in = new FileInputStream(file);
			
			OutputStream out = new FileOutputStream("gbk.txt");
			StringBuffer sb = new StringBuffer();
			int b =-1;
			byte [] by = new byte[1024];
			//b=in.read(by);//向字节数组中读入数据，返回实际读的字节个数
			while((b = in.read(by))!=-1){
				sb.append(new String(by,0,b,"utf-8"));    
			}
			byte[] bs =sb.toString().getBytes("gbk");
			out.write(bs);
			System.out.println(sb);
}
}
